package com.wtx.chapter06;

/**
 * @description: 从左到右求二进制幂
 * @author: wtx
 * @createDate: 2020/6/10
 */
public class LeftToRight {

    //array: a的幂次对应的二进制序列
    public static int solution(int a, int[] array){


        int res = a;
        for (int i = 1; i < array.length; i++) {

            res = res*res;
            if (array[i] == 1)
                res = res*a;
        }
        return res;
    }

    public static void main(String[] args) {
        // 2^4 = 16, 4->100
        int[] arr = {1,0,0};
        System.out.println(LeftToRight.solution(2,arr));    //16
    }
}
